package com.krain.ddbb.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.krain.corelibrary.helper.imageloader.ImageLoader;
import com.krain.ddbb.R;
import com.krain.ddbb.base.BaseActivity;
import com.krain.ddbb.entity.AppApi;
import com.krain.ddbb.entity.BaseEntity;
import com.krain.ddbb.entity.UserServer;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;

/**
 * Created by ex-kuangxiaomin101 on 2015-12-22.
 */
@EActivity(R.layout.activity_service_remark)
public class ServiceRemarkActivity extends BaseActivity implements RatingBar.OnRatingBarChangeListener {

    @ViewById(R.id.act_remark_iv_icon)
    ImageView mAvater;
    @ViewById(R.id.rating1)
    RatingBar r1;
    @ViewById(R.id.rating2)
    RatingBar r2;
    @ViewById(R.id.rating3)
    RatingBar r3;
    @ViewById(R.id.comment_text)
    EditText mComment;
    @ViewById(R.id.act_remark_tv_name)
    TextView mName;
    @ViewById(R.id.act_remark_phone)
    TextView mPhone;
    int score1, score2, score3;
    @Extra("bean")
    UserServer userServer;
    @Extra("id")
    String orderid;

    public static void jumpTothisActivity(Context context,String id,UserServer server){
        Intent intent = new Intent(context,ServiceRemarkActivity_.class);
        intent.putExtra("id",id);
        intent.putExtra("bean",server);
        context.startActivity(intent);
    }

    @Override
    protected String getToolbarTitle() {
        return "服务评价";
    }

    @AfterViews
    void afterViews() {
        r1.setOnRatingBarChangeListener(this);
        r2.setOnRatingBarChangeListener(this);
        r3.setOnRatingBarChangeListener(this);
        ImageLoader.getInstance(this).loadImage(mContext, mAvater, userServer.getPicture());
        mName.setText(userServer.getUsername());
        mPhone.setText(userServer.getPhone());

    }

    @Click(R.id.act_confirm_select_person)
    void submit() {
        if (mComment.getText().length() == 0) {
            baseUtil.showSnackBar(mContext, "评论内容不能为空");
            return;
        }
        showProgressDialog();
        showProgressDialog();
        sumitToComment();

    }

    @Background
    void sumitToComment(){
       BaseEntity entity = AppApi.getsInstance(mContext).comment(app.getmUserinfo().getAccess_token(),mComment.getText().toString(),score1,score2,score3
        ,String.valueOf(orderid));
        if (entity != null){
            baseUtil.showSnackBar(mContext,"评论成功");
        }
        dismissProgressDialog();
        finish();
    }



    @Override
    public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
        if (ratingBar == r1) {
            score1 = (int) rating;
        } else if (ratingBar == r2) {
            score2 = (int) rating;
        } else {
            score3 = (int) rating;
        }
    }
}
